import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.Arrays;


public class Test {

	public static void main(String[] args) {
		String2Hex();
		
		
	}
	public static void test(){
		String s1 = "abcABC我爱你";
		try {
			String s2  = new String(s1.getBytes("UTF-8"), "GB2312");
			System.out.println(s2);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		byte [] s3 =  s1.getBytes();
		System.out.println(Arrays.toString(s3));
		
		byte [] s4 = {97, 98, 99, 65, 66, 67, -26, -120, -111, -25, -120, -79, -28, -67, -96};
		String s5 = s4.toString();
		System.out.println(s5);
	}
	
	
	/***
	 * 字符串拼接
	 */
	public static void StringBunch(){
		String result = "";
		long num = 18800000000l;
		
		for (int j = 0; j < 2; j++) {
			long s = num + j;
			String ss = "" + s +",";
			result += ss;
		}
		System.out.println(result);
	}
	
	/***
	 * 字符串转化二进制、八进制字符串等
	 */
	public static void  String2Hex(){
		String pubkey = "123";  
		String prikey = "EMAY0220MG1SjWm0";
		byte[] bytes = EncryptionUtils.aesEncrypt(pubkey, prikey);
		
		System.out.println("将\"" + pubkey + "\"转为不同进制的字符串：");  
//		System.out.println("可以转换的进制范围：" + Character.MIN_RADIX + "-" + Character.MAX_RADIX);  
//		System.out.println("2进制："   + binary(bytes, 2));  
//		System.out.println("5进制："   + binary(bytes, 5));  
//		System.out.println("8进制："   + binary(bytes, 8));  
//		System.out.println("10进制："   + binary(bytes, 10));  
		System.out.println("16进制："  + binary(bytes, 16));  
		System.out.println("16进制："  + EncryptionUtils.parseByte2HexStr(bytes));  
//		System.out.println("32进制："  + binary(bytes, 32));  
//		System.out.println("64进制："  + binary(bytes, 64));// 这个已经超出范围，超出范围后变为10进制显示  
//		System.out.println(Arrays.toString(bytes));
		
		System.out.println(Arrays.toString(EncryptionUtils.parseHexStr2Byte(binary(bytes, 16))));
		System.out.println(EncryptionUtils.aesDecrypt(EncryptionUtils.parseHexStr2Byte(EncryptionUtils.parseByte2HexStr(bytes)), prikey));
		
		System.exit(0);  
	}
	
	/***
	 * 二进制数组转 radix 进制字符串
	 * @param bytes	二进制数组，byte数组
	 * @param radix	要转化的字符串进制
	 * @return 大写的 radix 进制字符串
	 */
	  public static String binary(byte[] bytes, int radix){  
	        return new BigInteger(1, bytes).toString(radix).toUpperCase();// 这里的1代表正数  
	    }  
	
	
}
